package tool

import (
	"fmt"

	"github.com/aliyun/alibaba-cloud-sdk-go/services/dysmsapi"
	common "jihe.common"
)

func SendSms(phone, code string) (err error) {
	client, err := dysmsapi.NewClientWithAccessKey("cn-hangzhou", common.Configer.Oss.AccessKeyId, common.Configer.Oss.AccessKeySecret)
	if err != nil {
		return
	}
	request := dysmsapi.CreateSendSmsRequest()
	request.Scheme = "https"
	request.PhoneNumbers = phone
	request.SignName = "芰荷科技"
	request.TemplateCode = "SMS_217440203"
	request.TemplateParam = fmt.Sprintf(`{"code":"%s"}`, code)
	_, err = client.SendSms(request)
	if err != nil {
		return
	}
	return nil
}
